/***************************************************************************
   Filename:    Brick.cpp
   Authors:     Josh Partridge and Joe Flowers
   Description: contains the brick class
****************************************************************************/

#include "brick.h"

/************************************************************************************
 Name:               Brick - constructors
 Description:        initialize various attributes of Brick
 Input:
               htlh: int representing health of brick
                  x: int representing x position of brick
                  y: int representing y position of brick
                  w: int representing width of brick
                  h: int representing height of brick
                  c: ink representing color of the brick
*************************************************************************************/
Brick::Brick(int hlth)
{
    health=hlth;
    color = white;
    setBounds(1,1,default_w,default_h);
}

Brick::Brick(int x, int y)
{
    health=1;
    color = white;

    setBounds(x,y,default_w,default_h);
}

Brick::Brick(int x, int y, ink c)
{
    health=1;
    color=c;
    setBounds(x,y,default_w,default_h);
}

Brick::Brick(int hlth, int x, int y)
{
    health=hlth;
    setBounds(x,y,default_w,default_h);
}

Brick::Brick(int hlth, int x, int y, ink c)
{
    health=hlth;
    color=c;
    setBounds(x,y,default_w,default_h);
}

Brick::Brick(int x, int y, int w, int h)
{
    health=1;
    color = white;

    setBounds(x,y,w,h);
}

Brick::Brick(int hlth, int x, int y, int w, int h)
{
    health=hlth;
    color = white;

    setBounds(x,y,w,h);
}

Brick::Brick(int hlth, int x, int y, int w, int h, ink c)
{
    health=hlth;
    color = c;

    setBounds(x,y,w,h);
}

/************************************************************************************
 Name:               setBounds
 Description:        setter for bounds (RECT attributes)
 Input:
                  x: int representing x position of brick
                  y: int representing y position of brick
                  w: int representing width of brick
                  h: int representing height of brick
*************************************************************************************/
void Brick::setBounds(int x, int y, int w, int h)
{
    bounds.left = x;
    bounds.right = x+w;
    bounds.top = y;
    bounds.bottom = y+h;
}

/************************************************************************************
 Name:               getBounds
 Description:        getter for bounds RECT
 Output:
             return: RECT (copy of bounds)
*************************************************************************************/
RECT Brick::getBounds()
{
    return bounds;
}

/************************************************************************************
 Name:               setHealth
 Description:        sets health of brick
 Input:
                  h: int representing health of brick
*************************************************************************************/
void Brick::setHealth(int h)
{
    health = h;
}

/************************************************************************************
 Name:               takeDamage
 Description:        modifies brick when it takes damage, including erasing it
 Input:
            damage: int representing amount to decrease health
             score: reference to game's score attribute (unsigned int)
*************************************************************************************/
void Brick::takeDamage(int damage, unsigned int &score)
{
    health-=damage;
    score+=50;
    if(health<=0)
        score+=50;
}

/************************************************************************************
 Name:               isAlive
 Description:        reports whether health > 0
 Output:
             return: bool representing whether health > 0
*************************************************************************************/
bool Brick::isAlive()
{
    if(health>0)
        return true;
    return false;
}

/************************************************************************************
 Name:               setColor
 Description:        sets brick's display color
 Input:
                  c: new color (ink)
*************************************************************************************/
void Brick::setColor(ink c)
{
    color = c;
}

/************************************************************************************
 Name:               display
 Description:        brick draws itself to the screen
 Input:
              brush: reference to game's Brush
*************************************************************************************/
void Brick::display(Brush &brush)
{

    brush.setColor(color);

    int width = bounds.right - bounds.left;
    int height = bounds.bottom - bounds.top;

    switch(health)
    {
        case -2:
        case -1:
        case 0: brush.clearBox(bounds.left, bounds.top, width+1, height+1); break;
        case 1: singleLineBox(brush,bounds.left,bounds.top,width,height);   break;
        case 2: doubleLineBox(brush,bounds.left,bounds.top,width,height);   break;
        default:break;
    }
}


